#2020年国赛-填空题 玩具蛇
flag = [[False] * 4 for _ in range(4)]  # 标记矩阵
dir = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0

def dfs(x, y, cnt):
    global ans
    if cnt == 16:  #填满16格
        ans += 1
        return
    for i, j in dir:
        dx, dy = x + i, y + j
        if 0 <= dx < 4 and 0 <= dy < 4 and not flag[dx][dy]:
            flag[dx][dy] = True  #占位，标记为已访问
            dfs(dx, dy, cnt + 1)
            flag[dx][dy] = False  # 回溯，取消标记

for i in range(4):
    for j in range(4):
        # 初始化每个起点
        flag[i][j] = True
        dfs(i, j, 1)
        flag[i][j] = False

print(ans)